package nl.utwente.eemcs.graphviz.util;


import java.util.List;

import nl.utwente.eemcs.graph.Graph;
import nl.utwente.eemcs.graph.GraphCollaboration;
import nl.utwente.eemcs.graphviz.GraphViz;
import nl.utwente.eemcs.graphviz.NewGraphVisualizer;


/**
 * Debugger class is used for debugging during the transformation
 * The class will be used to track the debugging process throughout the whole process
 * @author Evert Duipmans
 */
public class Debugger {
	private static boolean enabled = true;
	private static int imageCounter = 0;
	private static String outputPath = System.getProperty("user.dir");
	
	/**
	 * Enable the debugger
	 */
	public static void enableDebugger() {
		enabled = true;
	}
	
	/**
	 * Disable the debugger
	 */
	public static void disableDebugger() {
		enabled = false;
	}
	
	/**
	 * Check if the debugger is enabled
	 * @return True, if the debugger is enabled
	 */
	public static boolean isEnabled() {
		return enabled;
	}
	
	/**
	 * Set the output path for the graphs
	 * @param path Output path
	 */
	public static void setOutputPath(String path) {
		outputPath = path;
	}
	
	/**
	 * Print a debug line
	 * @param str Line
	 */
	public static void printDebug(String str) {
		if (enabled)
			System.out.println("[Debugger]" + str);
	}
	
	/**
	 * Print a line to the error stream
	 * @param str Line
	 */
	public static void printDebugError(String str) {
		if (enabled)
			System.err.println("[Debugger]" + str);
	}
	
	public static void drawImage(GraphCollaboration gc, String name) {
		if (enabled)
			GraphViz.createPNG(NewGraphVisualizer.generateDot(gc), "graph_" + imageCounter++ + "_" + name, outputPath);
	}
	
	public static void drawImage(Graph g, String name) {
		if (enabled) {
			String dot = NewGraphVisualizer.generateDot(g);
			GraphViz.createPNG(dot, "graph_" + imageCounter++ + "_" + name, outputPath);
		}
	}	
	
	public static void drawImage(List<Graph> graphs, String name) {
		if (enabled)
			GraphViz.createPNG(NewGraphVisualizer.generateDot(graphs), "graph_" + imageCounter++ + "_" + name, outputPath);
	}		
}
